package es.cea.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/LibroEditProcess")
public class LibroEditProcess extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		PrintWriter pw=response.getWriter();
		pw.print("<html><head></head><body>");
		pw.print("<h1 align='center'>Libro modificado</h1><hr><br><h2 align='center'>");
		
		try {
			Class.forName("com.mysql.jdbc.Driver");  
	    	Connection conexion = DriverManager.getConnection ("jdbc:mysql://localhost/libreria","root", "root");  
	    	Statement s = conexion.createStatement();  
	    		    	
	    	int update_count = s.executeUpdate("update libros set titulo='"+ request.getParameter("titulo")+"', fecha='"+ request.getParameter("fecha")+"' where id='"+ request.getParameter("id")+"' ");  
			
	    	s.close();
					
			
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {			
			e.printStackTrace();
		}  
		pw.print("<a href='ListadoLibros'>volver</a><br>");
		pw.println("</body></html>");
    	pw.close();
    	
	}


}
